<extend name="./_base"/>
<block name="css">

</block>
<block name="header">

</block>
<block name="menu">

</block>
<block name="content">
    <article class="page-container">

        <form class="form form-horizontal" id="form-getCard">
            <div class="row cl">
                <label class="form-label col-xs-3"><span class="c-red">*</span>选择游戏：</label>
                <div class="formControls col-xs-9">
                    <select name="gid" class="input-text">
                        <volist name="GameList" id="vo">
                            <option value="{$vo.id}">{$vo.name}</option>
                        </volist>
                    </select>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3"><span class="c-red">*</span>提取张数：</label>
                <div class="formControls col-xs-9">
                    <input type="number" class="input-text" value="1" placeholder="请填写您的游戏ID" id="num" name="num">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3"><span class="c-red">*</span>游戏ID：</label>
                <div class="formControls col-xs-9">
                    <input type="text" class="input-text" value="" placeholder="请填写您的游戏ID" id="game_id" name="game_id">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3"><span class="c-red">*</span>手机号：</label>
                <div class="formControls col-xs-9">
                    <input type="text" class="input-text" value="" placeholder="请填写用于开通本服务的手机号码" id="phone" name="phone">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3"><span class="c-red">*</span>手机验证码：</label>
                <div class="formControls col-xs-5">
                    <input type="text" class="input-text" value="" placeholder="请填写手机验证码" id="verify" name="verify">
                </div>
                <div class="formControls col-xs-4">
                    <button type="button" style="height: 31px" class="btn btn-block btn-primary radius"
                            onclick="getVerify(this)">获取验证码
                    </button>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3"><span class="c-red">*</span>图形验证码：</label>
                <div class="formControls col-xs-5">
                    <input type="text" class="input-text" value="" placeholder="点击图片刷新验证码" id="verifyImg"
                           name="verifyImg">
                </div>
                <div class="formControls col-xs-4">
                    <img src="{:U(verifyImg)}" alt="点击图片刷新验证码" style="width:100px;height: 32px;cursor: pointer"
                         onclick="this.src=this.src+'?'+Math.random()">
                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-5 col-xs-offset-3">
                    <input class="btn btn-primary btn-block radius" type="submit" value="&nbsp;&nbsp;提 取&nbsp;&nbsp;">
                </div>
            </div>
        </form>

        <div id="cardTable" style="display: none">
            <table class="table table-border table-bordered table-bg">
                <thead>
                <tr>
                    <th>卡号</th>
                    <th>密码</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </article>

</block>

<block name="script">

    <script type="text/javascript">
        function getVerify(obj) {
            var Interval;
            var allowTime = 60;
            var phone = $("#phone").val();

            function timer() {
                $(obj).text("剩余" + allowTime-- + "秒");
                if (allowTime < 0) {
                    clearInterval(Interval);
                    $(obj).removeClass("disabled");
                    $(obj).text("获取验证码");
                }

            }


            if (phone) {
                $.get('{:U(Verify)}?phone=' + phone, function (result) {
                    if (result.status == 1) {
                        var data = result.data;
                        if (data.allowTime)
                            allowTime = data.allowTime;

                        Interval = setInterval(timer, 1000);
                        $(obj).addClass("disabled");
                    }
                    alert(result.info);
                }, 'json');
            }
        }


        $(function () {


            var form=$('#form-getCard');
            form.validationEngine();

            $('.skin-minimal input').iCheck({
                checkboxClass: 'icheckbox-blue',
                radioClass: 'iradio-blue',
                increaseArea: '20%'
            });

            var flag = true;

            form.submit(function () {
                if ($(this).validationEngine('validate')) {
                    if (!flag) {
                        return false;
                    }
                    flag = false;
                    $.post("", $(this).serialize(), function (result) {
                        if (result.status == 1) {
                            var cardTable=$("#cardTable");
                            layer.msg(result.info);
                            $.each(result.data.table,function (i,item) {
                                cardTable.find("tbody").append('<tr><td>'+item.cno+'</td><td>'+item.cpwd+'</td></tr>');
                            });
                            cardTable.append('<a href="data:text/plain;base64,'+result.data.txt+'" download="点卡.txt">点击下载 </a>');
                            form.slideUp();
                            cardTable.fadeIn();
                        } else {
                            layer.alert(result.info, {icon: 5})
                        }
                        flag = true;
                    }, "json");
                }
                return false;
            });
        });
    </script>

</block>
